﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TierService;

using TierApplication;


namespace BasisMgr
{
    public partial class frmRegion : TierService.frmTemplate
    {
        public string _ProductID;

        public frmRegion()
        {
            InitializeComponent();
        }

        private void initForm()
        {
          
         }

        private void btnSearch_Click(object sender, EventArgs e)
        {            
            string ls_where = "";

            if ((txtRegionName.Text.Trim() != "") && (ckbRegionName.Checked))
                ls_where = ls_where + " RegionName  like '%" + txtRegionName.Text + "%'";

            T_Region mRegion = new T_Region();
            DataSet dsRegion = mRegion.GetList(ls_where);
            gcCustomer.DataSource = dsRegion.Tables[0];
            gvCustomer.ExpandAllGroups();
        }

        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            TierService.Utility.DataExportToExcel(gvCustomer, "省份信息");
        }


        private void gvCustomer_DoubleClick(object sender, EventArgs e)
        {
            if (gFuncType == Utility.FuncType.Select)
            {
                if (gvCustomer.RowCount < 1) return;
                DataRow dr = gvCustomer.GetDataRow(gvCustomer.FocusedRowHandle);
                _ProductID = dr["RegionID"].ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                btnQuery_Click(null, null);
            }
        }


        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (gvCustomer.RowCount < 1) return;
            if (MessageBox.Show("是否要删除此省份记录，删除后将无法恢复!", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                return;
            DataRow dr = gvCustomer.GetDataRow(gvCustomer.FocusedRowHandle);
            string sID = dr["RegionID"].ToString();

            T_Region mRegion = new T_Region();
            mRegion.Delete(sID);

            btnSearch_Click(null, null);
        }


        private void gvCustomer_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
                }
                else if (e.RowHandle < 0 && e.RowHandle > -1000)
                {
                    e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
                    e.Info.DisplayText = "G" + e.RowHandle.ToString();
                }
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            //frmProductDetail fDetail = new frmProductDetail();
            //fDetail.OpMode = TierService.Utility.OperateMode.Insert;
            //fDetail.gProductType = Utility.ProductType.Product;
            //fDetail.ShowDialog();

            //btnSearch_Click(null, null);
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            if (gvCustomer.RowCount < 1) return;
            DataRow dr = gvCustomer.GetDataRow(gvCustomer.FocusedRowHandle);
            string sID = dr["RegionID"].ToString();


            frmRegionDetail fDetail = new frmRegionDetail();
            fDetail.OpMode = TierService.Utility.OperateMode.Update;
            fDetail._RegionID = sID;
            if (fDetail.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                btnSearch_Click(null, null);
            }
        }

        private void frmProduct_Load(object sender, EventArgs e)
        {
            initForm();

        }

        private void gvCustomer_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (gvCustomer.RowCount < 1) return;
            DataRow dr = gvCustomer.GetDataRow(gvCustomer.FocusedRowHandle);
            //dr["IsChecked"] = (dr["IsChecked"] == "1") ? "0" : "1";
        }



        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            if (gvCustomer.RowCount < 1) return;
            DataRow dr = gvCustomer.GetDataRow(gvCustomer.FocusedRowHandle);
            string sID = dr["RegionID"].ToString();

            frmRegionDetail fDetail = new frmRegionDetail();
            fDetail.OpMode = TierService.Utility.OperateMode.Query;
            fDetail._RegionID = sID;
            fDetail.ShowDialog();
        }


    }
}